//
//  LoginViewController2.m
//  WebPDA
//
//  Created by Justin Yip on 10-7-26.
//  Copyright 2010 TenNights.com. All rights reserved.
//

#import "LoginViewController.h"
#import "LoginFormTableViewController.h"
#import "MainViewController.h"
#import <QuartzCore/QuartzCore.h>


@implementation LoginViewController

@synthesize scrollView;
//@synthesize imageView;
@synthesize loginForm;

-(IBAction)login:(id)sender {
	MainViewController *mainViewCtrl = [[MainViewController alloc] init];
	[self presentModalViewController:mainViewCtrl animated:YES];
	[mainViewCtrl release];
}
/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // Custom initialization
    }
    return self;
}
*/

- (void)viewWillAppear:(BOOL)animated {
	[super viewWillAppear:animated];
	
	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];	
}

- (void)viewWillDisappear:(BOOL)animated {
	[[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)keyboardDidShow:(NSNotification*)notif {
	NSLog(@"show keyboard");
	
	NSDictionary *userInfo = [notif userInfo];
	NSValue *aValue = [userInfo objectForKey:UIKeyboardBoundsUserInfoKey];
	CGSize keyboardSize = [aValue CGRectValue].size;
	CGRect viewFrame = self.view.frame;
	viewFrame.size.height -= keyboardSize.height;
	
	scrollView.frame = viewFrame;
	scrollView.backgroundColor = [UIColor redColor];
	/*
	NSLog(@"scroll frame, x%f,y%f,w%f,h%f",scrollView.frame.origin.x,
		  scrollView.frame.origin.y,
		  scrollView.frame.size.width,
		  scrollView.frame.size.height);*/
}

- (void)keyboardDidHide:(NSNotification*)notif {
	NSLog(@"hide keyboard");
	
	NSDictionary *userInfo = [notif userInfo];
	NSValue *aValue = [userInfo objectForKey:UIKeyboardBoundsUserInfoKey];
	CGSize keyboardSize = [aValue CGRectValue].size;
	CGRect viewFrame = self.view.frame;
	viewFrame.size.height += keyboardSize.height;
	
	scrollView.frame = viewFrame;
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.

- (void)viewDidLoad {
    [super viewDidLoad];
	
	scrollView.contentSize = self.view.frame.size;
	/*
	NSLog(@"frame, x%f,y%f,w%f,h%f",self.view.frame.origin.x,
		  self.view.frame.origin.y,
		  self.view.frame.size.width,
		  self.view.frame.size.height);
	NSLog(@"scroll frame, x%f,y%f,w%f,h%f",scrollView.frame.origin.x,
		  scrollView.frame.origin.y,
		  scrollView.frame.size.width,
		  scrollView.frame.size.height);
	NSLog(@"scroll content, w%f,h%f",
		  scrollView.contentSize.width,
		  scrollView.contentSize.height);*/
	
//	NSLog(@"image size,%f,h%f",
//		  imageView.image.size.width,
//		  imageView.image.size.height);
}


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
	[scrollView release];
	[loginForm release];
	//[imageView release];
	[super dealloc];
}


@end
